<script>
/**
 * 总是在新标签中打开链接
 */
import BaseMultiTab from './BaseMultiTab.vue'
export default {
  extends: BaseMultiTab,
  methods: {
    back (n) {
      const current = this.pages.find(p => p.fullPath == this.$route.fullPath),
        pages = [...this.pages]
      this.pages.length = 0
      pages.map(p => {
        if (p.fullPath != this.$route.fullPath) {
          this.pages.push(p)
        }
      })
      let page = this.pages[this.pages.length - 1]
      if (this.pages.length == 0) {
        page = this.getParent(current)
      }
      // 更新路由保持
      this.$store.updateKeepAlive(this.pages)
      this.$router.push({
        path: page.fullPath || page.path,
        replace: true
      })
    },
    getTabKey (page) {
      if (page?.meta?.target) {
        return page.name
      }
      return page.fullPath || page.path
    },
    handleRouteChange () {
      const current = this.pages.find(p => (p.fullPath || p.path) == this.$route.fullPath)
      this.activeKey = this.$route.fullPath
      if (!current) {
        this.pages.push(this.$route)
        this.$emit('tabChange', this.$route.fullPath, this.$route)
      }
      // 更新路由保持
      this.$store.updateKeepAlive(this.pages)
    },
    getTabTitle (page) {
      let title = page.meta.title
      if (page.meta.type == '3') {
        const parent = this.getParent(page)
        if (parent) {
          return `${parent.meta.title}-${title}`
        }
      }
      return title
    }
  }
}
</script>